package xiangmu1;
import java.util.Scanner;
public class Test2 {
    private static int num;//接受num6和num7的值

    public static int getNum() {
        return num;
    }

    public static void setNum(int num) {
        Test2.num = num;
    }
    //控制台输入
    Scanner scanner = new Scanner(System.in);
    //对象初始化
    User user = new User();
    //对象初始化
    Prices prices = new Prices();
    //加入车辆
    public void fun1() {
        System.out.println("请选择你要输入那类车：");
        System.out.println("1.轿车" + "\n" + "2.客车");
        int num3 = scanner.nextInt();
        switch (num3) {
            case 1:
                System.out.println("请输入车的名称：");
                Car1.jcar[4].setCarName(scanner.next());
                System.out.println("请输入车每日的租金：");
                Car1.jcar[4].setCarPrice(scanner.nextDouble());
                break;
            case 2:
                System.out.println("请输入车的名称：");
                Car1.pcar[4].setCarName(scanner.next());
                System.out.println("请输入车每日的租金：");
                Car1.pcar[4].setCarPrice(scanner.nextDouble());
                break;
        }
    }
    //下架车辆
    public void fun2() {
        System.out.println("请选择你要下架那类车：");
        System.out.println("1.轿车"+"\n"+"2.客车");
        int num4 = scanner.nextInt();
        switch (num4) {
            case 1:
                //try-catch-finally判断异常
                try{System.out.println("请输入你要下架轿车的序号：");
                    //for循环遍历
                    for (int i=scanner.nextInt()-1;i<Car1.jcar.length-1;i++){
                        Car1.jcar[i]=Car1.jcar[i+1];
                    }
                    Car1.jcar[Car1.jcar.length-1]=null;
                    for (int j=0;j<Car1.pcar.length;j++){
                        if (Car1.jcar[j].getCarName()!=null){
                            System.out.println(Car1.jcar[j].getCarName()+"\t"+Car1.jcar[j].getCarPrice()+"/天");
                        }
                    }
                }catch (Exception e){
                    System.out.println();
                }
                break;
            case 2:
                try{
                    System.out.println("请输入你要下架客车的序号：");
                    for (int i=scanner.nextInt()-1;i<Car1.pcar.length-1;i++){
                        Car1.pcar[i]=Car1.pcar[i+1];
                    }
                    Car1.pcar[Car1.pcar.length-1]=null;
                    for (int j=0;j<Car1.pcar.length;j++){
                        if (Car1.pcar[j].getCarName()!=null){
                            System.out.println(Car1.pcar[j].getCarName()+"\t"+Car1.pcar[j].getCarPrice()+"/天");
                        }
                    }
                }catch (Exception e){
                    System.out.println(" ");
                }
                break;
        }
    }
    //查看信息
    public void fun3(){
        System.out.println("1.轿车"+"\n"+"2.客车");
        int num2 = scanner.nextInt();
        switch (num2){
            case 1:
                for (int i=0;i<Car1.jcar.length;i++){
                    if (Car1.jcar[i].getCarName()!=null){
                        System.out.println(Car1.jcar[i].getCarName()+"\t"+Car1.jcar[i].getCarPrice()+"/天");
                    }
                }
                break;
            case 2:
                for (int j=0;j<Car1.pcar.length;j++){
                    if (Car1.pcar[j].getCarName()!=null){
                        System.out.println(Car1.pcar[j].getCarName()+"\t"+Car1.pcar[j].getCarPrice()+"/天");
                    }
                }
                break;
        }
    }
    //租车
    public void fun4(){
        System.out.println("请选择你要租的车类型：");
        System.out.println("1.轿车"+"\n"+"2.客车");
        int num5 = scanner.nextInt();
        switch (num5){
            case 1:
                for (int i=0;i<Car1.jcar.length;i++){
                    if (Car1.jcar[i].getCarName()!=null){
                        System.out.println(Car1.jcar[i].getCarName()+"\t"+Car1.jcar[i].getCarPrice()+"/天");
                    }
                }
                System.out.println("请选择你要租的车序号：");
                int num6 = scanner.nextInt();
                Test2.setNum(num6);
                System.out.println(Car1.jcar[num6-1].getCarName()+"\t"+Car1.jcar[num6-1].getCarPrice()+"/天");
                User.setMonny(Car1.jcar[num6-1].getCarPrice());
                System.out.println("请输入你要租的天数：");
                int num8 = scanner.nextInt();
                user.setDay(num8);
                prices.method(Car1.jcar[num6-1].getCarPrice(),num8);
                if (User.getMonny()>Jcar.getzMonny()){
                    System.out.println("你的余额不足请充值");
                }else{
                    System.out.println("你的余额为："+(Jcar.getzMonny()-User.getMonny()));
                }
                break;
            case 2:
                for (int j=0;j<Car1.pcar.length;j++){
                    if (Car1.pcar[j].getCarName()!=null){
                        System.out.println(Car1.pcar[j].getCarName()+"\t"+Car1.pcar[j].getCarPrice()+"/天");
                    }
                }
                System.out.println("请选择你要租的车序号：");
                int num7 = scanner.nextInt();
                Test2.setNum(num7);
                System.out.println(Car1.pcar[num7-1].getCarName()+"\t"+Car1.pcar[num7-1].getCarPrice()+"/天");
                User.setMonny(Car1.jcar[num7-1].getCarPrice());
                System.out.println("请输入你要租的天数：");
                int num9 = scanner.nextInt();
                user.setDay(num9);
                prices.method1(Car1.pcar[num7-1].getCarPrice(),num9);
                if (User.getMonny()>Jcar.getzMonny()){
                    System.out.println("你的余额不足请充值");
                }else{
                    System.out.println("你的余额为："+(Jcar.getzMonny()-User.getMonny()));
                }
                break;
        }
    }
    //还车
    public void fun5(){
        System.out.println("请选择你租的车类型：");
        System.out.println("1.轿车"+"\n"+"2.客车");
        int num10 = scanner.nextInt();
        switch (num10){
            case 1:
                System.out.println("恭喜你还车成功！");
                System.out.println("你在"+user.getDay()+"天的消费为："+User.getMonny()+"元");
                break;
            case 2:
                System.out.println("恭喜你还车成功！");
                System.out.println("你在"+user.getDay()+"天的消费为："+User.getMonny()+"元");
                break;
        }
    }
    //订单信息
    public void fun6(){
        System.out.println("请选择你租的车类型：");
        System.out.println("1.轿车"+"\n"+"2.客车");
        int num11 = scanner.nextInt();
        switch (num11){
            case 1:
                System.out.println("姓名:"+User1.user[1].getName()+"\t"+"车类型：轿车"+"\t"+"车名："+Car1.jcar[Test2.getNum()-1].getCarName()+"\t"+
                        "天数："+user.getDay()+"天"+"\t"+"总价："+User.getMonny()+"元");
                break;
            case 2:
                System.out.println("姓名:"+User1.user[1].getName()+"\t"+"车类型：客车"+"\t"+"车名："+Car1.pcar[Test2.getNum()-1].getCarName()+"\t"+
                        "天数："+user.getDay()+"天"+"\t"+"总价："+User.getMonny()+"元");
                break;
        }
    }
    //充值
    public void fun7(){
        System.out.println("请充值：");
        Jcar.setzMonny(scanner.nextInt());
        prices.method2();
    }
}

